#ifndef EXECUTOR_H
#define EXECUTOR_H

#include "compiler/planner.h"
#include "storage/buffer_pool.h"
#include "execution/catalog.h"
#include "execution/expression_evaluator.h"
#include <vector>
#include <memory>

class ExecutionResult {
public:
    bool success;
    std::string message;
    std::vector<std::vector<std::string>> rows;
};

class Executor {
public:
    Executor(std::unique_ptr<BufferPool>& bufferPool, std::shared_ptr<Catalog> catalog);

    ExecutionResult execute(const std::unique_ptr<Execution::PlanNode>& plan);

private:
    ExecutionResult executeCreateTable(const Execution::CreateTablePlan& plan);
    ExecutionResult executeInsert(const Execution::InsertPlan& plan);
    ExecutionResult executeSelect(const Execution::SelectPlan& plan);
    ExecutionResult executeDelete(const Execution::DeletePlan& plan);
    // Add executeUpdate method declaration after executeDelete
    ExecutionResult executeUpdate(const Execution::UpdatePlan& plan);

    std::unique_ptr<BufferPool>& bufferPool; // 使用引用，不获取所有权
    std::shared_ptr<Catalog> catalog;
    ExpressionEvaluator evaluator; // 表达式求值器实例
};

#endif // EXECUTOR_H
